package com.kai.service.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.kai.service.system.entity.RoleResource;
import com.kai.service.system.mapper.RoleResourceMapper;
import com.kai.service.system.service.IRoleResourceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 角色权限表 服务实现类
 * </p>
 *
 * @author wjk
 * @since 2021-12-11
 */
@Service
public class RoleResourceServiceImpl extends ServiceImpl<RoleResourceMapper, RoleResource> implements IRoleResourceService {

    /**
     * 根据角色id获取对应权限id
     *
     * @param roleId
     * @return
     */
    @Override
    public List<Integer> getResourceIdsByRoleId(Integer roleId) {
        return this.list(new LambdaQueryWrapper<RoleResource>().eq(RoleResource::getRoleId, roleId))
                .stream().map(RoleResource::getResourceId).collect(Collectors.toList());
    }

    /**
     * 根据资源id获取绑定角色
     *
     * @param resourceId
     * @return
     */
    @Override
    public List<Integer> getRoleIdsByResourceId(Integer resourceId) {
        return this.baseMapper.getRoleIdsByResourceId(resourceId);
//        return this.list(new LambdaQueryWrapper<RoleResource>().eq(RoleResource::getResourceId, resourceId))
//                .stream().map(RoleResource::getRoleId).collect(Collectors.toList());
    }

}
